// CameraWindow.cpp : implementation file
//

#include "stdafx.h"
#include "DesktopClient.h"
#include "CameraWindow.h"
#include "DialogAddDevice.h"


CCameraInfo::CCameraInfo(void)
{
	memset(wchCameraName, 0, sizeof(WCHAR) * 128);
	nFPS = 0;
	nResolution = 0;
	nBrightness = 0;
	nContrast = 0;
	nPTZX = 0;
	nPTZY = 0;
	nPTZZ = 0;
	nPTZZoom = 0;
	bIsPTZEnable = FALSE;
	bIsPreviewOn = FALSE;

	isOwnerState = 0;
}


CCameraInfo::~CCameraInfo(void)
{
	//	free(wchCameraName);
}

void CCameraInfo::SetCameraName(WCHAR* pCameraName)
{
	if (pCameraName)
		wsprintf(wchCameraName, pCameraName);
}

#define		UC_STATIC_TITLE			WM_USER + 0x1985
#define		UC_STATIC_CAMERANAME	UC_STATIC_TITLE + 0x0001
#define		UC_STATIC_FPS			UC_STATIC_CAMERANAME + 0x0001
#define		UC_STATIC_RESOLUTION	UC_STATIC_FPS + 0x0001
#define		UC_STATIC_CONTRAST		UC_STATIC_RESOLUTION + 0x0001
#define		UC_STATIC_PTZX			UC_STATIC_CONTRAST + 0x0001
#define		UC_STATIC_PTZY			UC_STATIC_PTZX + 0x0001
#define		UC_STATIC_PTZZ			UC_STATIC_PTZY + 0x0001
#define		UC_STATIC_PTZZOOM		UC_STATIC_PTZZ + 0x0001
#define		UC_SLIDER_BRIGHTNESS	UC_STATIC_PTZZOOM + 0x0001
#define		UC_CHECK_PREVIEW		UC_SLIDER_BRIGHTNESS + 0x0001
#define		UC_BUTTON_ADD_DEVICE	UC_CHECK_PREVIEW + 0x0001
#define		UC_BUTTON_REMOVE_DEVICE	UC_BUTTON_ADD_DEVICE + 0x0001
#define		UC_CONTROL_VIDEO		UC_BUTTON_REMOVE_DEVICE + 0x0001

WCHAR wchResolutions[][10] = {L"320x240", L"640x480"};
// CCameraWindow

IMPLEMENT_DYNAMIC(CCameraWindow, CWnd)

CCameraWindow::CCameraWindow()
{
	pCameraInfo = NULL;
	m_bIsCreated = FALSE;

	nOwnerIndex = -1;

	m_defFont.lfHeight =-27; 
	m_defFont.lfWidth =0; 
	m_defFont.lfEscapement=0; 
	m_defFont.lfOrientation=0; 
	m_defFont.lfWeight=FW_NORMAL; 
	m_defFont.lfItalic=FALSE; 
	m_defFont.lfUnderline=FALSE;
	m_defFont.lfStrikeOut=0; 
	m_defFont.lfCharSet=ANSI_CHARSET; 
	m_defFont.lfOutPrecision=OUT_OUTLINE_PRECIS; 
	m_defFont.lfClipPrecision=CLIP_DEFAULT_PRECIS; 
	m_defFont.lfQuality=DEFAULT_QUALITY; 
	m_defFont.lfPitchAndFamily=DEFAULT_PITCH | FF_SWISS; 
	swprintf(m_defFont.lfFaceName, 5, _T("Arial")); //_T("Arial"));

	m_cFont.CreatePointFont(90, _T("Arial"));

//	CBitmap buttonBmp;

//	buttonBmp.LoadBitmapW(IDB_BITMAP_ADD_DEVICE);
// 	m_imgAddButtons.Create(20, 20, ILC_COLOR32, 0, 0);
// 
// 	for (int i = 0; i < 4; i ++)
// 	{
// 		m_imgAddButtons.Add(&buttonBmp, 0xFFFFFF);
// 	}
// 	buttonBmp.DeleteObject();
// 
// 	buttonBmp.LoadBitmapW(IDB_BITMAP_REMOVE_DEVICE);
// 	m_imgRemoveButtons.Create(20, 20, ILC_COLOR32, 0, 0);
// 
// 	for (int i = 0; i < 4; i ++)
// 	{
// 		m_imgRemoveButtons.Add(&buttonBmp, 0xFFFFFF);
// 	}
// 	buttonBmp.DeleteObject();
}

CCameraWindow::~CCameraWindow()
{
	//DestroyAllControls();
}

void CCameraWindow::DestroyAllControls()
{
	if (stCameraName)
	{
		if (IsWindow(stCameraName->m_hWnd))
			stCameraName->DestroyWindow();
		delete stCameraName;
		stCameraName = NULL;
	}

	if (stVideoWindow)
	{
		if (IsWindow(stVideoWindow->m_hWnd))
			stVideoWindow->DestroyWindow();
		delete stVideoWindow;
		stVideoWindow = NULL;
	}

	if (stFPSTitle) 
	{
		if (IsWindow(stFPSTitle->m_hWnd))
			stFPSTitle->DestroyWindow();
		delete stFPSTitle;
		stFPSTitle = NULL;
	}

	if (cmbFPSValues)
	{
		if (IsWindow(cmbFPSValues->m_hWnd))
			cmbFPSValues->DestroyWindow();
		delete cmbFPSValues;
		cmbFPSValues = NULL;
	}

	if (stResolutionTitle)
	{
		if (IsWindow(stResolutionTitle->m_hWnd))
			stResolutionTitle->DestroyWindow();
		delete stResolutionTitle;
		stResolutionTitle = NULL;
	}

	if (cmbResolutionValues)
	{
		if (IsWindow(cmbResolutionValues->m_hWnd))
			cmbResolutionValues->DestroyWindow();
		delete cmbResolutionValues;
		cmbResolutionValues = NULL;
	}

	if (stBrightnessTitle)
	{
		if (IsWindow(stBrightnessTitle->m_hWnd))
			stBrightnessTitle->DestroyWindow();
		delete stBrightnessTitle;
		stBrightnessTitle = NULL;
	}

	if (scBrightness)
	{
		if (IsWindow(scBrightness->m_hWnd))
			scBrightness->DestroyWindow();
		delete scBrightness;
		scBrightness = NULL;
	}

	if (stContrastTitle) 
	{
		if (IsWindow(stContrastTitle->m_hWnd))
			stContrastTitle->DestroyWindow();
		delete stContrastTitle;
		stContrastTitle = NULL;
	}

	if (scContrast)
	{
		if (IsWindow(scContrast->m_hWnd))
			scContrast->DestroyWindow();
		delete scContrast;
		scContrast = NULL;
	}

	if (stPreviewTitle)
	{
		if (IsWindow(stPreviewTitle->m_hWnd))
			stPreviewTitle->DestroyWindow();
		delete stPreviewTitle;
		stPreviewTitle = NULL;
	}

	if (chkPreview)
	{
		if (IsWindow(chkPreview->m_hWnd))
			chkPreview->DestroyWindow();
		delete chkPreview;
		chkPreview = NULL;
	}

	if (stPTZTitle)
	{
		if (IsWindow(stPTZTitle->m_hWnd))
			stPTZTitle->DestroyWindow();
		delete stPTZTitle;
		stPTZTitle = NULL;
	}

	if (stPTZXTitle)
	{
		if (IsWindow(stPTZXTitle->m_hWnd))
			stPTZXTitle->DestroyWindow();
		delete stPTZXTitle;
		stPTZXTitle = NULL;
	}

	if (stPTZXValue)
	{
		if (IsWindow(stPTZXValue->m_hWnd))
			stPTZXValue->DestroyWindow();
		delete stPTZXValue;
		stPTZXValue = NULL;
	}

	if (stPTZYTitle)
	{
		if (IsWindow(stPTZYTitle->m_hWnd))
			stPTZYTitle->DestroyWindow();
		delete stPTZYTitle;
		stPTZYTitle = NULL;
	}

	if (stPTZYValue)
	{
		if (IsWindow(stPTZYValue->m_hWnd))
			stPTZYValue->DestroyWindow();
		delete stPTZYValue;
		stPTZYValue = NULL;
	}

	if (stPTZZTitle)
	{
		if (IsWindow(stPTZZTitle->m_hWnd))
			stPTZZTitle->DestroyWindow();
		delete stPTZZTitle;
		stPTZZTitle = NULL;
	}

	if (stPTZZValue)
	{
		if (IsWindow(stPTZZValue->m_hWnd))
			stPTZZValue->DestroyWindow();
		delete stPTZZValue;
		stPTZZValue = NULL;
	}

	if (stPTZZoomTitle)
	{
		if (IsWindow(stPTZZoomTitle->m_hWnd))
			stPTZZoomTitle->DestroyWindow();
		delete stPTZZoomTitle;
		stPTZZoomTitle = NULL;
	}

	if (stPTZZoomValue)
	{
		if (IsWindow(stPTZZoomValue->m_hWnd))
			stPTZZoomValue->DestroyWindow();
		delete stPTZZoomValue;
		stPTZZoomValue = NULL;
	}

// 	for (int i = 0; i < 4; i ++)
// 	{
// 		m_imgAddButtons.Remove(i);
// 		m_imgRemoveButtons.Remove(i);
// 	}
// 	m_imgAddButtons.DeleteImageList();
// 	m_imgRemoveButtons.DeleteImageList();
// 
// 	if (btnAddDevice)
// 	{
// 		if (IsWindow(btnAddDevice->m_hWnd))
// 			btnAddDevice->DestroyWindow();
// 		delete btnAddDevice;
// 		btnAddDevice = NULL;
// 	}
// 
// 	if (btnRemoveDeivce)
// 	{
// 		if (IsWindow(btnRemoveDeivce->m_hWnd))
// 			btnRemoveDeivce->DestroyWindow();
// 		delete btnRemoveDeivce;
// 		btnRemoveDeivce = NULL;
// 	}
	
}

void CCameraWindow::DrawAllControls()
{
	// Camera name
	stCameraName = new CStatic();
	if (!stCameraName->Create(_T("Camera"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 300, 30), this, UC_STATIC_CAMERANAME)) 
	{
		delete stCameraName;
		stCameraName = NULL;
	} 
	else
	{
		stCameraName->SetFont(&m_cFont);
	}

	// VideoWindow
	stVideoWindow = new CVideoWindow();
	if (!stVideoWindow->Create(NULL, _T("VideoWindow"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 320, 240), this, UC_CONTROL_VIDEO)) 
	{
		delete stVideoWindow;
		stVideoWindow = NULL;
	}

	// FPS title
	stFPSTitle = new CStatic();
	if (!stFPSTitle->Create(_T("FPS :"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 50, 30), this, UC_STATIC_TITLE))
	{
		delete stFPSTitle;
		stFPSTitle = NULL;
	}
	else 
	{
		stFPSTitle->SetFont(&m_cFont);
	}

	// FPS value	
	cmbFPSValues = new CComboBox();
	if (!cmbFPSValues->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(0, 0, 100, 30), this, UC_STATIC_FPS))
	{
		delete cmbFPSValues;
		cmbFPSValues = NULL;
	}
	else 
	{
		CString tmpString;
		for (int i = 0; i < 30; i ++)
		{
			tmpString.Format(_T("%d"), i + 1);
			cmbFPSValues->AddString(tmpString);
		}
		cmbFPSValues->SetFont(&m_cFont);
	}

	// Resolution title
	stResolutionTitle = new CStatic();
	if (!stResolutionTitle->Create(_T("Resolution :"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stResolutionTitle;
		stResolutionTitle = NULL;
	}
	else 
	{
		stResolutionTitle->SetFont(&m_cFont);
	}

	// Resolution value
	cmbResolutionValues = new CComboBox();
	if (!cmbResolutionValues->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(0, 0, 50, 30), this, UC_STATIC_RESOLUTION))
	{
		delete cmbResolutionValues;
		cmbResolutionValues = NULL;
	} 
	else 
	{		
		cmbResolutionValues->AddString(wchResolutions[0]);
		cmbResolutionValues->AddString(wchResolutions[1]);
		cmbResolutionValues->SetFont(&m_cFont);
	}

	// Brightness title
	stBrightnessTitle = new CStatic();
	if (!stBrightnessTitle->Create(_T("Brightness :"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 100, 30), this, UC_STATIC_TITLE))
	{
		delete stBrightnessTitle;
		stBrightnessTitle = NULL;
	}
	else 
	{
		stBrightnessTitle->SetFont(&m_cFont);
	}

	// Brightness value
	scBrightness = new CSliderCtrl();
	if (!scBrightness->Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 50, 30), this, UC_SLIDER_BRIGHTNESS))
	{
		delete scBrightness;
		scBrightness = NULL;
	} 
	else 
	{
		scBrightness->SetFont(&m_cFont);
	}

	// Contrast title
	stContrastTitle = new CStatic();
	if (!stContrastTitle->Create(_T("Contrast :"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 100, 30), this, UC_STATIC_TITLE))
	{
		delete stContrastTitle;
		stContrastTitle = NULL;
	} 
	else 
	{
		stContrastTitle->SetFont(&m_cFont);
	}

	// Contrast value
	scContrast = new CSliderCtrl();
	if (!scContrast->Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 50, 20), this, UC_STATIC_CONTRAST)) 
	{
		delete scContrast;
		scContrast = NULL;
	} 
	else 
	{
		scContrast->SetFont(&m_cFont);
	}
	
	// Preview title
	stPreviewTitle = new CStatic();
	if (!stPreviewTitle->Create(_T("Preview :"), WS_CHILD | WS_VISIBLE | SS_LEFT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stPreviewTitle;
		stPreviewTitle = NULL;
	}
	else 
	{
		stPreviewTitle->SetFont(&m_cFont);
	}

	// Preview value
	chkPreview = new CButton();
	if (!chkPreview->Create(_T("On/Off"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, CRect(0, 0, 50, 20), this, UC_CHECK_PREVIEW))
	{
		delete chkPreview;
		chkPreview = NULL;
	} 
	else 
	{
		chkPreview->SetFont(&m_cFont);
	}

	// PTZ title
	stPTZTitle = new CStatic();
	if (!stPTZTitle->Create(_T("Pan/Tilt/Zoom"), WS_CHILD | WS_VISIBLE | SS_RIGHT, CRect(0, 0, 150, 20), this, UC_STATIC_TITLE))
	{
		delete stPTZTitle;
		stPTZTitle = NULL;
	}
	else 
	{
		stPTZTitle->SetFont(&m_cFont);
	}

	// PTZ X title
	stPTZXTitle = new CStatic();
	if (!stPTZXTitle->Create(_T("X :"), WS_CHILD | WS_VISIBLE | SS_RIGHT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stPTZXTitle;
		stPTZXTitle = NULL;
	}
	else 
	{
		stPTZXTitle->SetFont(&m_cFont);
	}

	// PTZ X value
	stPTZXValue = new CEdit();
	if (!stPTZXValue->Create(WS_VISIBLE | WS_CHILD | ES_RIGHT | WS_BORDER, CRect(0, 0, 50, 20), this, UC_STATIC_PTZX))
	{
		delete stPTZXValue;
		stPTZXValue = NULL;
	}

	// PTZ Y title
	stPTZYTitle = new CStatic();
	if (!stPTZYTitle->Create(_T("Y :"), WS_CHILD | WS_VISIBLE | SS_RIGHT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stPTZYTitle;
		stPTZYTitle = NULL;
	}

	// PTZ Y value
	stPTZYValue = new CEdit();
	if (!stPTZYValue->Create(WS_VISIBLE | WS_CHILD | ES_RIGHT | WS_BORDER, CRect(0, 0, 50, 20), this, UC_STATIC_PTZY))
	{
		delete stPTZYValue;
		stPTZYValue = NULL;
	}

	// PTZ Z title
	stPTZZTitle = new CStatic();
	if (!stPTZZTitle->Create(_T("Z :"), WS_CHILD | WS_VISIBLE | SS_RIGHT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stPTZZTitle;
		stPTZZTitle = NULL;
	}

	// PTZ Z value
	stPTZZValue = new CEdit();
	if (!stPTZZValue->Create(WS_VISIBLE | WS_CHILD | ES_RIGHT | WS_BORDER, CRect(0, 0, 50, 20), this, UC_STATIC_PTZZ))
	{
		delete stPTZZValue;
		stPTZZValue = NULL;
	}

	// PTZ Zoom title
	stPTZZoomTitle = new CStatic();
	if (!stPTZZoomTitle->Create(_T("Zoom :"), WS_CHILD | WS_VISIBLE | SS_RIGHT, CRect(0, 0, 100, 20), this, UC_STATIC_TITLE))
	{
		delete stPTZZoomTitle;
		stPTZZoomTitle = NULL;
	}

	// PTZ Zoom value
	stPTZZoomValue = new CEdit();
	if (!stPTZZoomValue->Create(WS_VISIBLE | WS_CHILD | ES_RIGHT | WS_BORDER, CRect(0, 0, 50, 20), this, UC_STATIC_PTZZOOM))
	{
		delete stPTZZoomValue;
		stPTZZoomValue = NULL;
	}

	// Add device Button
	btnAddDevice = new CClientButton();
	if (!btnAddDevice->Create(_T("+"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, WM_USER + 0x1000))
	{
		delete btnAddDevice;
		btnAddDevice = NULL;
	} 
	else 
	{
		//btnAddDevice->SetIcon(IDR_MAINFRAME);
		btnAddDevice->OffsetColor(CClientButton::BTNST_COLOR_BK_IN, 30);
		btnAddDevice->SetColor(CClientButton::BTNST_COLOR_FG_IN, RGB(0, 128, 0));
		btnAddDevice->SetAlign(CClientButton::ST_ALIGN_HORIZ);
		btnAddDevice->m_nActionType = CClientButton::BTNST_ACTION_ADD_DEVICE;
	}

	// Remove device Button
	btnRemoveDeivce = new CClientButton();
	if (!btnRemoveDeivce->Create(_T("-"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, WM_USER + 0x1001))
	{
		delete btnRemoveDeivce;
		btnRemoveDeivce = NULL;
	}
	else 
	{
		//btnRemoveDeivce->SetIcon(IDR_MAINFRAME);
		btnRemoveDeivce->OffsetColor(CClientButton::BTNST_COLOR_BK_IN, 30);
		btnRemoveDeivce->SetColor(CClientButton::BTNST_COLOR_FG_IN, RGB(0, 128, 0));
		btnRemoveDeivce->SetAlign(CClientButton::ST_ALIGN_HORIZ);
		btnRemoveDeivce->m_nActionType = CClientButton::BTNST_ACTION_REMOVE_DEVICE;
	}
	ResizeForControls();
}

void CCameraWindow::ResizeForControls()
{
	CRect rcClient;
	this->GetWindowRect(&rcClient);
	int nWidth = rcClient.Width();
	int nHeight = rcClient.Height();

	if (stPreviewTitle)
		stPreviewTitle->MoveWindow(10, nHeight - 25, 80, 20, TRUE);
	if (chkPreview)
		chkPreview->MoveWindow(95, nHeight - 25, 75, 20, TRUE);
	if (stPTZZoomTitle)
		stPTZZoomTitle->MoveWindow(175, nHeight - 25, 55, 20, TRUE);
	if (stPTZZoomValue)
		stPTZZoomValue->MoveWindow(235, nHeight - 25, 70, 20, TRUE);

	nHeight -= 25;
	if (stContrastTitle)
		stContrastTitle->MoveWindow(10, nHeight - 25, 80, 20, TRUE);
	if (scContrast)
		scContrast->MoveWindow(95, nHeight - 25, 75, 20, TRUE);
	if (stPTZZTitle)
		stPTZZTitle->MoveWindow(175, nHeight - 25, 55, 20, TRUE);
	if (stPTZZValue)
		stPTZZValue->MoveWindow(235, nHeight - 25, 70, 20, TRUE);

	nHeight -= 25;
	if (stBrightnessTitle)
		stBrightnessTitle->MoveWindow(10, nHeight - 25, 80, 20, TRUE);
	if (scBrightness)
		scBrightness->MoveWindow(95, nHeight - 25, 80, 20, TRUE);
	if (stPTZYTitle)
		stPTZYTitle->MoveWindow(175, nHeight - 25, 55, 20, TRUE);
	if (stPTZYValue)
		stPTZYValue->MoveWindow(235, nHeight - 25, 70, 20, TRUE);

	nHeight -= 25;
	if (stResolutionTitle)
		stResolutionTitle->MoveWindow(10, nHeight - 25, 80, 20, TRUE);
	if (cmbResolutionValues)
		cmbResolutionValues->MoveWindow(95, nHeight - 25, 75, 20, TRUE);
	if (stPTZXTitle)
		stPTZXTitle->MoveWindow(175, nHeight - 25, 55, 20, TRUE);
	if (stPTZXValue)
		stPTZXValue->MoveWindow(235, nHeight - 25, 70, 20, TRUE);

	nHeight -= 25;
	if (stFPSTitle)
		stFPSTitle->MoveWindow(10, nHeight - 25, 80, 20, TRUE);
	if (cmbFPSValues)
		cmbFPSValues->MoveWindow(95, nHeight - 25, 75, 20, TRUE);
	if (stPTZTitle)
		stPTZTitle->MoveWindow(175, nHeight - 25, 130, 20, TRUE);

	if (stCameraName)
		stCameraName->MoveWindow(10, 10, 150, 20);

	if (stVideoWindow)
		stVideoWindow->MoveWindow(0, 40, 320, 240);

	if (btnAddDevice)
		btnAddDevice->MoveWindow(nWidth - 10 - 20 * 2, 10, 20, 20, TRUE);

	if (btnRemoveDeivce)
		btnRemoveDeivce->MoveWindow(nWidth - 5 - 20, 10, 20, 20, TRUE);
}

void CCameraWindow::SetCameraInfo(CCameraInfo* cameraInfoTemp)
{
	if (cameraInfoTemp != NULL)
		pCameraInfo = cameraInfoTemp;
}

void CCameraWindow::SetVariableForControls()
{
	if (pCameraInfo == NULL)
		return;

	CString tmpStr;
	if (pCameraInfo->wchCameraName) 
	{
		stCameraName->SetWindowTextW(pCameraInfo->wchCameraName);
	}

	tmpStr.Format(L"%d", pCameraInfo->nFPS);
	//stFPSValue->SetWindowTextW(tmpStr);

	tmpStr.Format(L"%d", pCameraInfo->nResolution);
	//stResolutionValue->SetWindowTextW(tmpStr);

	scBrightness->SetPos(pCameraInfo->nBrightness);

	tmpStr.Format(L"%d", pCameraInfo->nContrast);
	//stContrastValue->SetWindowTextW(tmpStr);

	if (pCameraInfo->bIsPreviewOn) 
		chkPreview->SetCheck(1);

	if (pCameraInfo->bIsPTZEnable == FALSE)
	{
		stPTZXValue->SetWindowTextW(L"");
		stPTZXValue->EnableWindow(FALSE);

		stPTZYValue->SetWindowTextW(L"");
		stPTZYValue->EnableWindow(FALSE);

		stPTZZValue->SetWindowTextW(L"");
		stPTZZValue->EnableWindow(FALSE);

		stPTZZoomValue->SetWindowTextW(L"");
		stPTZZoomValue->EnableWindow(FALSE);
	} 
	else 
	{
		tmpStr.Format(L"%d", pCameraInfo->nPTZX);
		stPTZXValue->SetWindowTextW(tmpStr);

		tmpStr.Format(L"%d", pCameraInfo->nPTZY);
		stPTZYValue->SetWindowTextW(tmpStr);

		tmpStr.Format(L"%d", pCameraInfo->nPTZZ);
		stPTZZValue->SetWindowTextW(tmpStr);

		tmpStr.Format(L"%d", pCameraInfo->nPTZZoom);
		stPTZZoomValue->SetWindowTextW(tmpStr);
	}
}

BEGIN_MESSAGE_MAP(CCameraWindow, CWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

// CCameraWindow message handlers

int CCameraWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	DrawAllControls();
	m_bIsCreated = TRUE;
	return 0;
}


void CCameraWindow::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	ResizeForControls();
}


void CCameraWindow::OnDestroy()
{
	CWnd::OnDestroy();

	DestroyAllControls();
}

void CCameraWindow::OnAddDeviceClick()
{
	this->GetParent()->PostMessageW(WM_NOTIFY_BUTTON_CLICK, WM_ADD_CHANNEL, (DWORD_PTR)&nOwnerIndex);
	return;
}

void CCameraWindow::OnRemoveDeviceClick()
{
	this->GetParent()->PostMessageW(WM_NOTIFY_BUTTON_CLICK, WM_REMOVE_CHANNEL, (DWORD_PTR)&nOwnerIndex);
	return;
}

BOOL CCameraWindow::PreTranslateMessage(MSG* pMsg)
{
	switch (pMsg->message)
	{
	case WM_NOTIFY_BUTTON_CLICK:
		if (pMsg->wParam == WM_LBUTTONDOWN)
		{
			int *nActionType = (int*)pMsg->lParam;
			if (*nActionType == CClientButton::BTNST_ACTION_ADD_DEVICE)
			{
				OnAddDeviceClick();
				return TRUE;
			}
			else if (*nActionType == CClientButton::BTNST_ACTION_REMOVE_DEVICE) 
			{
				OnRemoveDeviceClick();
				return TRUE;
			}
		}
		break;
	default:
		break;
	}

	return CWnd::PreTranslateMessage(pMsg);
}
